/**
 * Created by Administrator on 2017/6/30 0030.
 */
"use strict";

angular.module('app.sensor').controller('LoginLogCtrl', function ($scope, $http) {

    //配置分页基本参数
    $scope.paginationConf = {
        currentPage: 1,
        itemsPerPage: 10,
        pagesLength: 5,
        totalItems: 20,
        perPageOptions: [10, 20, 30, 50, 1000],
        timefrom:'',
        timeto:'',
        info_name:'',
        onChange: function () {
        }
    };
    $scope.sends = function () {
        var page_obj = {
            page:$scope.paginationConf.currentPage,
            rows:$scope.paginationConf.itemsPerPage     
        }
        var info_name = $scope.paginationConf.info_name;
        var tid = $scope.paginationConf.timefrom;
        var toid = $scope.paginationConf.timeto;
        var query = '?info_name='+info_name+'&time='+tid+','+toid;
        $http.post(baseurl+'/list/select/logfile'+query,page_obj).then(function(res){
            // console.log(res.data);
            if (res.data.ret = 1) {
                var arr = res.data.rows; 
                for (var i = 0; i < arr.length; i++) {
                    var obj = arr[i];
                    var time = obj.time;
                    obj.time = moment(time).format("YYYY-MM-DD HH:mm:ss");
                    if (obj.time == 'Invalid date') {
                        obj.time = time;
                    }

                }
                $scope.datas = arr;
                $scope.paginationConf.totalItems = res.data.records;
            }
        })
    }

    $scope.exportData = function () {

        var blob = new Blob(["\ufeff" + document.getElementById('exportable').innerHTML], {
            type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8"
        });

        saveAs(blob, "Report.xls");
    };


    var leave = function () {
        window.location.href = "about:blank";
        window.close()
        // socket.emit('leave', 'leave');
    }


    $scope.$watch('paginationConf.currentPage + paginationConf.itemsPerPage',$scope.sends);

});

